"""
购物系统业务需求V2.0：
1.	现在用户在进商场之前需要从10张优惠券中，随机抽取一张优惠券。
比如抽到一个空凋的8折优惠券，后面在购物的过程中，空凋就可以按照8折后的价格来购买。
2.	优化购物小条的人性化打印。
	购物时间，卡余额，购物数量，购买总商品的价值。
3.	添加退货功能。在购买途中，某个商品不要了，退回到购物架中！
"""
import random
import time

MONEY = 1000
money = 1000
price = [300, 500]
products = ['矿泉水', '面包']
shopping = []
discount = [['矿泉水', 9], ['矿泉水', 8], ['矿泉水', 7], ['矿泉水', 6], ['矿泉水', 5], ['面包', 9], ['面包', 8],
            ['面包', 7], ['面包', 6], ['面包', 5]]
r = random.randint(1, 9)
print('抽到优惠券：{}的{}折优惠券'.format(discount[r][0], discount[r][1]))
isUsed = False
buy = input('请输入购买的物品：')

while (buy != 'q') & (buy != 'Q'):
    count = 0
    p = 0
    for i in range(len(products)):
        if buy == products[i]:
            if (buy == discount[r][0]) & (~isUsed):
                if money >= price[i] * 0.1 * discount[r][1]:
                    shopping.append(buy)
                    p = price[i] * 0.1 * discount[r][1]
                    money -= p
                    isUsed = True
                    print('恭喜，购买成功！您的卡余额还剩', money)
                else:
                    print('穷鬼，钱不够！请到其他超市购买！')
                    break
            else:
                if money >= price[i]:
                    shopping.append(buy)
                    p = price[i]
                    money -= p
                    print('恭喜，购买成功！您的卡余额还剩', money)
                else:
                    print('穷鬼，钱不够！请到其他超市购买！')
                    break
            back = input('是否退货？')
            if back == '是':
                money += p
                del shopping[i]
                print('退货成功！')
            break
        else:
            count += 1
            if count == len(products):
                print('没有这个商品，别瞎弄！')
    buy = input('请输入购买的物品：')
print('购物小条：')
print('购物时间：', time.strftime("%Y-%m-%d %H:%M:%S", time.localtime()))
print('卡余额：', money)
print('购物数量：', len(shopping))
print('购买总商品的价值', MONEY - money)
